package cn.dzhang.rcp.hyperbola.preferences;

import org.eclipse.core.runtime.preferences.ConfigurationScope;
import org.eclipse.jface.preference.BooleanFieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.eclipse.ui.preferences.ScopedPreferenceStore;

import cn.dzhang.rcp.hyperbola.Activator;

public class GeneralPreferencePage extends FieldEditorPreferencePage implements
		IWorkbenchPreferencePage {

	private static final ScopedPreferenceStore SCOPED_PREFERENCE_STORE = new ScopedPreferenceStore(
			ConfigurationScope.INSTANCE, Activator.PLUGIN_ID);
	public static final String AUTO_LOGIN = "auto login";
	public static final String PROMPT_ON_EXIT = "prompt on exit";
	public static final String ID = "cn.dzhang.rcp.hyperbola.preferences.GeneralPreferencePage";

	/**
	 * Create the preference page.
	 */
	public GeneralPreferencePage() {
		super(FLAT);

	}

	@Override
	protected IPreferenceStore doGetPreferenceStore() {
		return SCOPED_PREFERENCE_STORE;
	}

	/**
	 * Create contents of the preference page.
	 */
	@Override
	protected void createFieldEditors() {
		addField(new BooleanFieldEditor(AUTO_LOGIN, "Auto Login at Startup",
				BooleanFieldEditor.DEFAULT, getFieldEditorParent()));
		addField(new BooleanFieldEditor(PROMPT_ON_EXIT, "Prompt on Exit",
				BooleanFieldEditor.DEFAULT, getFieldEditorParent()));
	}

	@Override
	public boolean performOk() {
		try {
			SCOPED_PREFERENCE_STORE.save();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return super.performOk();
	}

	/**
	 * Initialize the preference page.
	 */
	@Override
	public void init(IWorkbench workbench) {
	}

}
